home *** CD-ROM | disk | FTP | other *** search
- #pragma once
- //
- // stopwatch, a class to measure intervals up to about 35 minutes in length with
- // a maximal resolution of 20 microseconds (see IM VI, The Time Manager for details)
- //
- // 'read' and 'stop' return the number of microseconds since 'start' or zero
- // if the elapsed time is too great or 'start' wasn't called at all.
- // The utility function 'seconds' converts those times into seconds.
- //
- class stopwatch : public TMTask
- {
- public:
- stopwatch();
- ~stopwatch();
- void start();
- long read();
- double seconds();
- double milliseconds();
- double microseconds();
-
- long stop();
-
- static double seconds( long stopwatch_result);
- static double milliseconds( long stopwatch_result);
- static double microseconds( long stopwatch_result);
-
- private:
- static const long starting_value;
- int running;
-
- void restart( unsigned long to_go);
- };
-
- inline void stopwatch::start()
- {
- restart( starting_value);
- }
-
- inline double stopwatch::seconds()
- {
- return ((double) read()) / 1000000.0;
- }
-
- inline double stopwatch::milliseconds()
- {
- return ((double) read()) / 1000.0;
- }
-
- inline double stopwatch::microseconds()
- {
- return (double) read();
- }
-
- inline double stopwatch::seconds( long stopwatch_result)
- {
- return ((double) stopwatch_result) / 1000000.0;
- }
-
- inline double stopwatch::milliseconds( long stopwatch_result)
- {
- return ((double) stopwatch_result) / 1000.0;
- }
-
- inline double stopwatch::microseconds( long stopwatch_result)
- {
- return (double) stopwatch_result;
- }
-